<template>
	<div class="login-container dis">
		<div class="normal-left" />
		<div style="flex: 1;">
			<el-form v-if="!loading" ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form"
				autocomplete="on" label-position="left">
				<div class="title-container">
					<h3 class="title">找回密码</h3>
				</div>
				<div class="foSi14 mar-bott5">用户名/手机号</div>
				<el-form-item prop="username" class="mar-bott30">
					<el-input ref="username" v-model="loginForm.username" placeholder="请填写用户名/手机号" name="username"
						type="text" tabindex="1" autocomplete="on" />
				</el-form-item>
				<div class="foSi14 mar-bott5">验证码</div>
				<el-form-item prop="code" class="mar-bott30">
					<el-input ref="code" v-model="loginForm.code" style="width: 75%;" placeholder="请输入验证码" name="code"
						type="text" tabindex="1" autocomplete="on" />
					<span class="svg-container cuPo">获取验证码</span>
				</el-form-item>
				<el-button :loading="loading" type="primary" class="borRad40"
					style="width:100%;margin-bottom:30px;background: #6b7cdd;border: 0;"
					@click.native.prevent="handleLogin">下一步</el-button>
			</el-form>
			<el-form v-else ref="loginForm1" :model="loginForm1" :rules="loginRules1" class="login-form"
				autocomplete="on" label-position="left">
				<div class="title-container">
					<h3 class="title">修改密码</h3>
				</div>
				<div class="foSi14 mar-bott5">密码</div>
				<el-form-item prop="password" class="mar-bott30">
					<el-input ref="password" v-model="loginForm1.password" type="password" placeholder="请输入密码"
						name="password" tabindex="2" autocomplete="on" @keyup.enter.native="handleLogin1" />
				</el-form-item>
				<div class="foSi14 mar-bott5">确认密码</div>
				<el-form-item prop="passwordQ" class="mar-bott30">
					<el-input ref="passwordQ" v-model="loginForm1.passwordQ" type="password" placeholder="请再次输入新密码"
						name="passwordQ" tabindex="2" autocomplete="on" @keyup.enter.native="handleLogin1" />
				</el-form-item>
				<el-button :loading="loading1" type="primary" class="borRad40"
					style="width:100%;margin-bottom:30px;background: #6b7cdd;border: 0;"
					@click.native.prevent="handleLogin1">完成</el-button>
			</el-form>
		</div>
	</div>
</template>

<script>
	import {
		validTel
	} from '@/utils/validate'

	export default {
		name: 'RetakePassword',
		components: {},
		data() {
			const validateUsername = (rule, value, callback) => {
				if (!value) {
					callback(new Error('请填写正确手机号'))
				} else {
					callback()
				}
			}
			const validateCode = (rule, value, callback) => {
				if (value.length <= 0) {
					callback(new Error('请输入验证码'))
				} else {
					callback()
				}
			}
			const validatePassword = (rule, value, callback) => {
				if (value.length < 6) {
					callback(new Error('请填写正确密码'))
				} else {
					callback()
				}
			}
			const validatePasswordQ = (rule, value, callback) => {
				if (value !== this.loginForm1.password) {
					callback(new Error('密码不一致'))
				} else {
					callback()
				}
			}
			return {
				loginForm: {
					username: '',
					code: ''
				},
				loginRules: {
					username: [{
						required: true,
						trigger: 'blur',
						validator: validateUsername
					}],
					code: [{
						required: true,
						trigger: 'blur',
						validator: validateCode
					}]
				},
				loading: false,
				loginForm1: {
					password: '',
					passwordQ: ''
				},
				loginRules1: {
					password: [{
						required: true,
						trigger: 'blur',
						validator: validatePassword
					}],
					passwordQ: [{
						required: true,
						trigger: 'blur',
						validator: validatePasswordQ
					}]
				},
				loading1: false
			}
		},
		created() {
			// window.addEventListener('storage', this.afterQRScan)
		},
		methods: {
			handleLogin() {
				this.$refs.loginForm.validate(valid => {
					if (valid) {
						this.loading = true
					} else {
						console.log('error submit!!')
						return false
					}
				})
			},
			handleLogin1() {
				this.$refs.loginForm1.validate(valid => {
					if (valid) {
						this.loading1 = true
						this.$router.push(`/login`)
					} else {
						console.log('error submit!!')
						return false
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	/* 修复input 背景不协调 和光标变色 */
	/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

	$bg: #283443;
	$light_gray: #fff;
	$cursor: #fff;

	@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
		.login-container .el-input input {
			// color: $cursor;
		}
	}

	/* reset element-ui css */
	.login-container {
		.el-input {
			display: inline-block;
			height: 40px;

			input {
				background: transparent;
				border: 0px;
				-webkit-appearance: none;
				border-radius: 0px;
				padding: 12px 5px 12px 15px;
				// color: $light_gray;
				height: 40px;
				// caret-color: $cursor;

				&:-webkit-autofill {
					box-shadow: 0 0 0px 1000px $bg inset !important;
					// -webkit-text-fill-color: $cursor !important;
				}
			}
		}

		.el-form-item {
			// border: 1px solid rgba(255, 255, 255, 0.1);
			border: 1px solid #f2f2f2;
			// background: rgba(0, 0, 0, 0.1);
			border-radius: 5px;
			color: #000;
		}
	}
</style>

<style lang="scss" scoped>
	$bg: #2d3a4b;
	$dark_gray: #889aa4;
	$light_gray: #eee;

	.login-container {
		height: 100%;
		width: 100%;
		// background-color: $bg;
		overflow: hidden;

		.normal-left {
			width: 640px;
			height: 100%;
			background: url('../../icons/png/aac4b1ee0969d44a27cec7e39e3ca61.jpg') no-repeat left top;
			background-size: cover;
		}

		.login-form {
			position: relative;
			width: 520px;
			max-width: 100%;
			padding: 160px 35px 0;
			margin: 0 auto;
			overflow: hidden;
		}

		.tips {
			font-size: 14px;
			// color: #fff;
			margin-bottom: 10px;

			span {
				&:first-of-type {
					margin-right: 16px;
				}
			}
		}

		.svg-container {
			vertical-align: middle;
			display: inline-block;
			text-align: center;
			width: 25%;
			color: #6b7cdd;
		}

		.title-container {
			position: relative;

			.title {
				font-size: 26px;
				// color: $light_gray;
				margin: 0px auto 40px auto;
				// text-align: center;
				font-weight: bold;
			}

			.set-language {
				// color: #fff;
				position: absolute;
				top: 3px;
				font-size: 18px;
				right: 0px;
				cursor: pointer;
			}
		}

		.show-pwd {
			position: absolute;
			right: 10px;
			top: 7px;
			font-size: 16px;
			// color: $dark_gray;
			cursor: pointer;
			user-select: none;
		}

		.thirdparty-button {
			position: absolute;
			right: 0;
			bottom: 6px;
		}

		@media only screen and (max-width: 470px) {
			.thirdparty-button {
				display: none;
			}
		}

		.custom-checkbox {
			display: inline-block;
			width: 16px;
			height: 16px;
			vertical-align: sub;
			margin-right: 8px;
			background: #f2f2f2;
			border-radius: 2px;
			cursor: pointer;
		}

		.custom-checkbox-default {
			background: #f2f2f2;
			border-radius: 2px;
		}

		.custom-checkbox-sel {
			background: url(https://img.keepyoga.com/assets/img_cloud/radio-selected.png) no-repeat;
			background-size: contain;
		}

		.forget-password {
			margin-left: auto;
			color: #bbb;
		}
	}
</style>